package com.laotang.第_10_章_二叉搜索树.力扣_230_二叉搜索树中第K小的元素;

import com.laotang.第_10_章_二叉搜索树.TreeNode;

public class _230_kth_smallest_element_in_a_bst {

    private int k;
    private int res;

    public int kthSmallest(TreeNode root, int k) {
        this.k = k;
        inOrder(root);
        return res;
    }

    private void inOrder(TreeNode node) {
        if (node == null) return;

        inOrder(node.left);
        k--;
        if (k == 0) {
            res = node.val;
            return;
        }
        inOrder(node.right);
    }

}
